// dataUrl转blobUrl;

export function dataUrlToBlobUrl(dataUrl, imageType = "png") {
  const base64String = dataUrl.substr(dataUrl.indexOf(",") + 1);
  const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
  const base64 = (base64String + padding)
    .replace(/\-/g, "+")
    .replace(/_/g, "/");

  const rawData = window.atob(base64);
  const outputArray = new Uint8Array(rawData.length);

  for (let i = 0; i < rawData.length; ++i) {
    outputArray[i] = rawData.charCodeAt(i);
  }
  const blobUrl = window.URL.createObjectURL(
    new Blob([outputArray], { type: "image/" + imageType })
  );
  return blobUrl;
}
